package com.kaifamiao.singleton;

/**
 * 懒汉式单例
 */
public class Moon {
	
	public static String name ;
	private static Moon moon ;
	
	static {
		System.out.println( "static" );
		name = "月球" ;
	}
	
	private Moon() {
		super();
		System.out.println( "创建Moon实例" );
	}
	
	// 存在线程安全问题
	public static Moon getInstance() {
		if( moon == null ) {
			moon = new Moon();
		}
		return moon ;
	}

	public void welcome() {
		System.out.println( "欢迎来到月球" );
	}
}
